//
// Created by fairy on 2025/7/1.
//
#pragma once
#include "LT768/LT768_Demo.hpp"
#include "LT768/LT768_Lib.hpp"

#include <core_common.hpp>
#include <cstring>
#include <delay.hpp>
#include <hal.hpp>
#include <utils/coroutine.hpp>
#include <LT768/LT768.hpp>
// ======================== 属性 ==========================

namespace core
{
    using test_pin = hal::gpio::portA::pin7;
    // 取别名
    using  coroutine = utils::coroutine<hal::systick::get_tick>;

}


// ======================== 子任务 ==========================

namespace core
{

    inline coroutine::asynctask test_coroutine_task()
    {
        float test =0.2f;
        while (true) {
            test_pin::clear();
            co_await coroutine::awaitable{10};
            test_pin::set();
            co_await coroutine::awaitable{10};
            test +=0.1f;
            test *=2.1f;//FPU
            if (test >=10 )
                test=0;
        }
    }
}
constexpr uint32_t row = 1024;
constexpr uint32_t col = 10;

// inline unsigned char pixel_data[col*row*2]={};

// ======================== 核心逻辑 ==========================
namespace core
{

    class control
    {
    public:
        ALWAYS_INLINE static void init()
        {
            test_pin cfg;
           cfg.initializer().mode.output().pull.none().speed.high();

            // 协程入口
            // test_coroutine_task();

            // memset(pixel_data,0xffff,row*col*2);
            // LT768_Init();
            // for (int i=0;i<600/col;++i) {
            //     // MPU8_16bpp_Memory_Write_dma(0, i*col, row, col, pixel_data);
            //     MPU8_16bpp_Memory_Write_dma_lvgl(0, i*col, row-1, (i+1)*col-1, pixel_data);
            //     // delay::ms(50);
            // }


            // MPU8_16bpp_Memory_Write_dma(500, 0, 100, 200, pixel_data);
            // delay::ms(50);
            // MPU8_16bpp_Memory_Write_dma(500, 0, 100, 200, pixel_data);
        }
        ALWAYS_INLINE static void handler()
        {
            // coroutine::scheduler_poll();
            // MPU8_16bpp_Memory_Write_dma(0, 0, 100, 100, pixel_data);
            // hal::delay::ms(1000);

            // LT768_DMA_24bit_Block(1, 0, 0, 0,LCD_XSIZE_TFT,LCD_YSIZE_TFT,LCD_XSIZE_TFT,Picture_1_Addr);
            // hal::delay::ms(1000);
            // MPU16_16bpp_Memory_Write(0, 0, 99, 99, pixel_data);
            // hal::delay::ms(1000);

            // LT768_DMA_24bit_Block(1, 0, 0, 0,LCD_XSIZE_TFT,LCD_YSIZE_TFT,LCD_XSIZE_TFT,Picture_2_Addr);
            // hal::delay::ms(1000);
            // LT768_DMA_24bit_Block(1, 0, 0, 0,LCD_XSIZE_TFT,LCD_YSIZE_TFT,LCD_XSIZE_TFT,Picture_3_Addr);
            // hal::delay::ms(1000);
            // LT768_DMA_24bit_Block(1, 0, 0, 0,LCD_XSIZE_TFT,LCD_YSIZE_TFT,LCD_XSIZE_TFT,Picture_4_Addr);
            // hal::delay::ms(1000);
            // LT768_DrawSquare_Fill(0, 0,LCD_XSIZE_TFT,LCD_YSIZE_TFT,color16M_red);
            // hal::delay::ms(1000);
            // LT768_DrawSquare_Fill(0, 0,LCD_XSIZE_TFT,LCD_YSIZE_TFT,color16M_green);
            // hal::delay::ms(1000);
            // LT768_DrawSquare_Fill(0, 0,LCD_XSIZE_TFT,LCD_YSIZE_TFT,color16M_blue);
            // hal::delay::ms(1000);
            // LT768_DrawSquare_Fill(0, 0,LCD_XSIZE_TFT,LCD_YSIZE_TFT,color16M_gray);
            // hal::delay::ms(1000);
            // display_gray16_H();
            // LT768_DrawSquare(0, 0,LCD_XSIZE_TFT - 1,LCD_YSIZE_TFT - 1,color16M_red);
            // hal::delay::ms(1000);
            // LT768_DrawSquare_Fill(0, 0,LCD_XSIZE_TFT,LCD_YSIZE_TFT,color16M_black);
            // hal::delay::ms(1000);
            // LT768_DrawSquare_Fill(0, 0,LCD_XSIZE_TFT,LCD_YSIZE_TFT,color16M_white);
            // LT768_Select_Internal_Font_Init(32, 1, 1, 0, 1);
            // LT768_Print_Internal_Font_String(30, 90,color16M_red,color16M_white, "Waiken-Smart STM32F427 TEST BOARD");
            // LT768_Print_Internal_Font_String(30, 130,color16M_red,color16M_white, "LCD:7.0inch_1024X600");
            // LT768_Print_Internal_Font_String(30, 170,color16M_red,color16M_white, "TOUCH IC:FT5446U");
            // LT768_Print_Internal_Font_String(30, 210,color16M_red,color16M_white, "FW:V10 @2023-5-2");
            // hal::delay::ms(1000);
        }
    };
}

